<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <script src="../js/jsonAjax.js"></script>
    <link rel="stylesheet" href="../css/myequipment.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../js/fontzize.js"></script>

    <link rel="stylesheet" href="../css/weixinlogo.css">
</head>
<body>
<div id="app">
    <section>
        <div class="logo"><img src="../imgs/loginimg.png" alt=""></div>
        <div class="title">绑定后可直接点击微信登录？？？？
           <br> 绑定后此微信号不可解绑或再次绑定其他账户</div>
        <input type="button" class="signin signinup" value="绑定已有账号" onclick="yiyouzhan()">
        <input type="button" class="signin" value="绑定新账号" onclick="xinzhan()">
    </section>

</div>
<script type="text/javascript">
    (function () {
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)return(r[2]);
            return null;
        }
        var myurl = GetQueryString("openid=");
        if (myurl != null && myurl.toString().length > 1) {
            var openid = GetQueryString("openid=");
        }
        var myurl = GetQueryString("nickname=");
        if (myurl != null && myurl.toString().length > 1) {
            var nickname = GetQueryString("nickname=");
        }
        var myurl = GetQueryString("sex");
        if (myurl != null && myurl.toString().length > 1) {
            var sex = GetQueryString("sex=");
        }
        var myurl = GetQueryString("language=");
        if (myurl != null && myurl.toString().length > 1) {
            var language = GetQueryString("language=");
        }
        var myurl = GetQueryString("city");
        if (myurl != null && myurl.toString().length > 1) {
            var city = GetQueryString("city=");
        }
        var myurl = GetQueryString("province=");
        if (myurl != null && myurl.toString().length > 1) {
            var province = GetQueryString("province=");
        }
        var myurl = GetQueryString("country=");
        if (myurl != null && myurl.toString().length > 1) {
            var country = GetQueryString("country=");
        }
        var myurl = GetQueryString("headimgurl=");
        if (myurl != null && myurl.toString().length > 1) {
            var headimgurl = GetQueryString("headimgurl=");
        }
        var myurl = GetQueryString("unionid=");
        if (myurl != null && myurl.toString().length > 1) {
            var unionid = GetQueryString("unionid=");
        }
        console.log(openid!=undefined&&unionid!=undefined)
        if(openid!=undefined&&unionid!=undefined){
            setTimeout(function () {
                var device_id = [{
                    keyname: "weixin",
                    usermsg: {
                        city: decodeURIComponent(city),
                        country: decodeURIComponent(country),
                        headimgurl: headimgurl,
                        language: language,
                        nickname: decodeURIComponent(nickname),
                        openid: openid,
                        province: decodeURIComponent(province),
                        sex:Number(sex),
                        unionid: unionid
                    }
                }
                ];
                setstages(device_id);
                //接口名称 06 微信授权登录√
                jsonAjax("/Home/User/api_login_wechat",
                    {
                        city:decodeURIComponent(city),
                        country:decodeURIComponent(country),
                        headimgurl:headimgurl,
                        nickname:decodeURIComponent(nickname),
                        openid:openid,
                        province:decodeURIComponent(province),
                        sex:Number(sex),
                        unionid:unionid,
                    }
                ).done(function (data) {
                    console.log(data)
                    if(data.data.uid==0){
                    }if(data.data.uid!=0){
                        var usermsg=[{
                            keyname:"user",
                            usermsg:data.data
                        }];
                        setstages(usermsg);
                        setTimeout(function(){
                            window.location.href=golinks("medicationplan.html");
                        },150)

                    }

                })
            },200)
        }else {

        }



    })();
    function yiyouzhan() {
        window.location.href="weixntelister.html"

    };
    function xinzhan() {
        window.location.href="telregister.html"

    }
</script>

</body>
</html>